package com.course.action;

import java.io.IOException;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.commons.beanutils.BeanUtils;

import com.course.bean.CourseTo;
import com.course.delegate.CourseMgrDelegate;
import com.course.exception.DataNotFoundException;
import com.course.formbean.CourseFormBean;
import com.course.util.UtilConstants;


public class viewCourseMaterialAction extends HttpServlet {

	
	private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
                doPost(request, response);
	}
public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
               
		CourseFormBean cb=new CourseFormBean();
				Map map=request.getParameterMap();
			try {
				BeanUtils.populate(cb, map);
			} catch (IllegalAccessException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (InvocationTargetException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
				
				
			}
		        String path="";
		        Vector<CourseTo> courseInfo=null;

			  try{
				    try{
				   courseInfo= new CourseMgrDelegate().viewCourse();				  								 
				    }catch (DataNotFoundException e) {
						e.printStackTrace();
					}
				  
				  System.out.println("in Action class vcb..........."+courseInfo);
				  
				  
				  if(!courseInfo.isEmpty()){    
					  request.setAttribute("coursematerial", courseInfo);
					  request.setAttribute("status", UtilConstants._COURSE_INFO);
					  path=UtilConstants._UPLOAD_MATERIAL;
					 }
				  else {
					  request.setAttribute("status", UtilConstants._NO_COURSE_INFO);
					  path=UtilConstants._UPLOAD_MATERIAL;
					  }
				  }
			  catch (NullPointerException e) {
				  request.setAttribute("status", UtilConstants._INVALIED_DATA);
				  path=UtilConstants._UPLOAD_MATERIAL;
				e.printStackTrace();
				}
			RequestDispatcher rd=request.getRequestDispatcher(path);
				rd.forward(request,response);
		
	}

}
